package eleme.openapi.sdk.oauth.parser;

import eleme.openapi.sdk.oauth.response.ErrorResponse;

/**
 * @author me
 */
public class ObjectJsonParser<T extends ErrorResponse> implements OAuthParser<T> {

    private Class<T> clazz;
    private boolean simplify;

    public ObjectJsonParser(Class<T> clazz) {
        this.clazz = clazz;
    }

    public ObjectJsonParser(Class<T> clazz, boolean simplify) {
        this.clazz = clazz;
        this.simplify = simplify;
    }

    @Override
    public T parse(String rsp) {
        Converter converter;
        converter = this.simplify ? new SimplifyJsonConverter() : new JsonConverter();
        return converter.toResponse(rsp, clazz);
    }

    @Override
    public Class<T> getResponseClass() {
        return clazz;
    }

}
